package com.example.homework;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

public class ContactInfoActivity extends AppCompatActivity {
    private TextView firstnameView;
    private TextView lastnameView;
    private TextView phoneView;
    private ImageButton callButton;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contact_info_layout);
        setTitle("联系人详情");
        this.firstnameView=findViewById(R.id.firstname_view);
        this.lastnameView=findViewById(R.id.lastname_view);
        this.phoneView=findViewById(R.id.phone_view);
        this.callButton=findViewById(R.id.call_button);

        Intent intent=getIntent();
        String firstname=intent.getStringExtra("firstname");
        String lastname=intent.getStringExtra("lastname");
        String phone=intent.getStringExtra("phone");
        this.firstnameView.setText(firstname);
        this.lastnameView.setText(lastname);
        this.phoneView.setText(phone);
        this.callButton.setOnClickListener(v->{
            call();
        });
    }
    private void call(){
        Intent intent=new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:"+this.phoneView.getText().toString()));
        startActivity(intent);
    }

}
